package com.scsj.supermarket.presenter;

import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.AddAndAlterDeliveryAddressBase;
import com.scsj.supermarket.base.ForgetPasswordBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.model.AddAndAlterDeliveryAddressModel;
import com.scsj.supermarket.model.ForgetPasswordModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 新增和修改收货地址presenter
 */

public class ForgetPasswordPresenter extends BasePresenter implements ForgetPasswordBase.IPresenter {

    private ForgetPasswordBase.IModel mModel;
    private ForgetPasswordBase.IView mView;

    public ForgetPasswordPresenter(ForgetPasswordBase.IView view) {
        mView = view;
        mModel = new ForgetPasswordModel();
    }


    @Override
    public void deliverSendAuthCodeData(RequestBody requestBody) {
        addSubscription(mModel.getSendAuthCodeData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.AuthCodeSuccessMsg("验证码发送成功", result);
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverSetNewPwdData(RequestBody requestBody) {
        addSubscription(mModel.getSetNewPwdData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.AddSetNewPwsSuccessMsg("设置新密码成功", result);
                    Logger.d("设置新密码成功" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }
}
